package com.linkcld.demo.web;

import com.linkcld.demo.config.SsoProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private SsoProperty ssoProperty;

    @Value("${sso.server.hostUrl}")
    private String ssoServerHostUrl;



    /**
     * 获取当前登录用户信息.
     *
     * @return 当前登录用户信息
     */

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public User getCurrentLoginUser() {
        System.out.println("ssoServerHostUrl--------------" + ssoServerHostUrl);
        System.out.println(12314214);
        System.out.println(ssoProperty.getClient());
        User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    }


    @ResponseBody
    @RequestMapping(value = "/test" , method = RequestMethod.GET)
    public User getCurrentLoginUser2() {

//        System.out.println(ssoProperty.getClient());
        return ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    }
}
